/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package bpmn.impl;

import bpmn.BpmnPackage;
import bpmn.BusinessProcessDiagram;
import bpmn.Expression;
import bpmn.Reusable;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.eclipse.emf.ecore.util.EObjectResolvingEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Reusable</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link bpmn.impl.ReusableImpl#getDiagramRef <em>Diagram Ref</em>}</li>
 *   <li>{@link bpmn.impl.ReusableImpl#getProcessRef <em>Process Ref</em>}</li>
 *   <li>{@link bpmn.impl.ReusableImpl#getInputMaps <em>Input Maps</em>}</li>
 *   <li>{@link bpmn.impl.ReusableImpl#getOutMaps <em>Out Maps</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class ReusableImpl extends SubProcessImpl implements Reusable {
	/**
	 * The cached value of the '{@link #getDiagramRef() <em>Diagram Ref</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getDiagramRef()
	 * @generated
	 * @ordered
	 */
	protected BusinessProcessDiagram diagramRef;

	/**
	 * The cached value of the '{@link #getProcessRef() <em>Process Ref</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getProcessRef()
	 * @generated
	 * @ordered
	 */
	protected bpmn.Process processRef;

	/**
	 * The cached value of the '{@link #getInputMaps() <em>Input Maps</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getInputMaps()
	 * @generated
	 * @ordered
	 */
	protected EList<Expression> inputMaps;

	/**
	 * The cached value of the '{@link #getOutMaps() <em>Out Maps</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getOutMaps()
	 * @generated
	 * @ordered
	 */
	protected EList<Expression> outMaps;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected ReusableImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return BpmnPackage.Literals.REUSABLE;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public BusinessProcessDiagram getDiagramRef() {
		if (diagramRef != null && diagramRef.eIsProxy()) {
			InternalEObject oldDiagramRef = (InternalEObject)diagramRef;
			diagramRef = (BusinessProcessDiagram)eResolveProxy(oldDiagramRef);
			if (diagramRef != oldDiagramRef) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, BpmnPackage.REUSABLE__DIAGRAM_REF, oldDiagramRef, diagramRef));
			}
		}
		return diagramRef;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public BusinessProcessDiagram basicGetDiagramRef() {
		return diagramRef;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setDiagramRef(BusinessProcessDiagram newDiagramRef) {
		BusinessProcessDiagram oldDiagramRef = diagramRef;
		diagramRef = newDiagramRef;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, BpmnPackage.REUSABLE__DIAGRAM_REF, oldDiagramRef, diagramRef));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public bpmn.Process getProcessRef() {
		if (processRef != null && processRef.eIsProxy()) {
			InternalEObject oldProcessRef = (InternalEObject)processRef;
			processRef = (bpmn.Process)eResolveProxy(oldProcessRef);
			if (processRef != oldProcessRef) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, BpmnPackage.REUSABLE__PROCESS_REF, oldProcessRef, processRef));
			}
		}
		return processRef;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public bpmn.Process basicGetProcessRef() {
		return processRef;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setProcessRef(bpmn.Process newProcessRef) {
		bpmn.Process oldProcessRef = processRef;
		processRef = newProcessRef;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, BpmnPackage.REUSABLE__PROCESS_REF, oldProcessRef, processRef));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Expression> getInputMaps() {
		if (inputMaps == null) {
			inputMaps = new EObjectResolvingEList<Expression>(Expression.class, this, BpmnPackage.REUSABLE__INPUT_MAPS);
		}
		return inputMaps;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Expression> getOutMaps() {
		if (outMaps == null) {
			outMaps = new EObjectResolvingEList<Expression>(Expression.class, this, BpmnPackage.REUSABLE__OUT_MAPS);
		}
		return outMaps;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case BpmnPackage.REUSABLE__DIAGRAM_REF:
				if (resolve) return getDiagramRef();
				return basicGetDiagramRef();
			case BpmnPackage.REUSABLE__PROCESS_REF:
				if (resolve) return getProcessRef();
				return basicGetProcessRef();
			case BpmnPackage.REUSABLE__INPUT_MAPS:
				return getInputMaps();
			case BpmnPackage.REUSABLE__OUT_MAPS:
				return getOutMaps();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case BpmnPackage.REUSABLE__DIAGRAM_REF:
				setDiagramRef((BusinessProcessDiagram)newValue);
				return;
			case BpmnPackage.REUSABLE__PROCESS_REF:
				setProcessRef((bpmn.Process)newValue);
				return;
			case BpmnPackage.REUSABLE__INPUT_MAPS:
				getInputMaps().clear();
				getInputMaps().addAll((Collection<? extends Expression>)newValue);
				return;
			case BpmnPackage.REUSABLE__OUT_MAPS:
				getOutMaps().clear();
				getOutMaps().addAll((Collection<? extends Expression>)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case BpmnPackage.REUSABLE__DIAGRAM_REF:
				setDiagramRef((BusinessProcessDiagram)null);
				return;
			case BpmnPackage.REUSABLE__PROCESS_REF:
				setProcessRef((bpmn.Process)null);
				return;
			case BpmnPackage.REUSABLE__INPUT_MAPS:
				getInputMaps().clear();
				return;
			case BpmnPackage.REUSABLE__OUT_MAPS:
				getOutMaps().clear();
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case BpmnPackage.REUSABLE__DIAGRAM_REF:
				return diagramRef != null;
			case BpmnPackage.REUSABLE__PROCESS_REF:
				return processRef != null;
			case BpmnPackage.REUSABLE__INPUT_MAPS:
				return inputMaps != null && !inputMaps.isEmpty();
			case BpmnPackage.REUSABLE__OUT_MAPS:
				return outMaps != null && !outMaps.isEmpty();
		}
		return super.eIsSet(featureID);
	}

} //ReusableImpl
